/* 
 * 练习12：将练习9的所有类，都添加一个dispose()方法，有层次地调用这个方法。
 * PS:堪称完美的对象生成、销毁顺序演示！  
 */
package chapter7_Reusing; 
import publicLibs.p;

class Component11 {
	Component11(byte b) { p.p("Component11(byte)"); }
	void dispose(){
		p.p("Componet11 is disposing itself...");
	}
}

class Component22 {
	Component22(short s) { p.p("Component22(short)"); }
	void dispose(){
		p.p("Componet22 is disposing itself...");
	}
}

class Component33 {
	Component33(int i) { p.p("Component33(int)"); }
	void dispose(){
		p.p("Componet33 is disposing itself...");
	}
}

class Root1 {
	Component11 c1root;
	Component22 c2root;
	Component33 c3root;
	Root1(float f) {
		c1root = new Component11((byte)0);
		c2root = new Component22((short)0);
		c3root = new Component33(0);
		p.p("Root(foat)"); 
	}
	void dispose(){
		p.p("Root1 is disposing itself...");
		c3root.dispose();
		c2root.dispose();
		c1root.dispose();
	}
}

public class E12_Stem9 extends Root1 { 
	Component11 c1stem10;
	Component22 c2stem10;
	Component33 c3stem10;
	E12_Stem9(double d) { 
		super(2.78f);
		c1stem10 = new Component11((byte)1);
		c2stem10 = new Component22((short)1);
		c3stem10 = new Component33(1);
		p.p("Stem10(double)"); 
	}
	
	void dispose(){
		p.p("E12_Stem9 is disposing itself...");
		c3stem10.dispose();
		c2stem10.dispose();
		c1stem10.dispose();
		super.dispose();
	}
	public static void main(String[] args) {
		E12_Stem9 x = new E12_Stem9(2.78);
		x.dispose();
	}
}
